-- =============================================
-- Table: user_role
-- Purpose:	Will store information for users mapping to roles of the system
-- Author: Dale McFarlane
-- Created: 2013-1-17
-- Modification History
-- Modified By	Modification Date	Reason
-- =====================================================================================
--  
-- =====================================================================================

SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

SET ANSI_PADDING ON
GO

CREATE TABLE [dbo].[user_role](
	[user_id] bigint NOT NULL,
	[role_id] bigint NOT NULL,
	[created_date] [datetime] NOT NULL,
	[modified_date] [datetime] NULL,
	CONSTRAINT [pkn_user_role] PRIMARY KEY CLUSTERED 
	(
		[user_id] ASC
	)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

ALTER TABLE user_role
	ADD CONSTRAINT 
		fk_user_role_role_id FOREIGN KEY (role_id) REFERENCES [role](role_id)ON UPDATE CASCADE
GO

/*
ALTER TABLE user_role
	DROP CONSTRAINT 
		fk_user_role_role_id
GO
*/

ALTER TABLE user_role
	ADD CONSTRAINT 
		fk_user_role_user_id FOREIGN KEY (user_id) REFERENCES [user](user_id) ON UPDATE CASCADE
GO
/*
ALTER TABLE user_role
	DROP CONSTRAINT 
		fk_user_role_user_id 
GO
*/

SET ANSI_PADDING ON
GO